#include "account.h"
#include <iostream>
#include <fstream>
#include<string>
#include <iomanip>
using namespace std;

account::account()
{
}

int account::create_account()
{
	int l = 0;
	account ac;
	cout << "\n\t\t\tEnter The account No. :";
	cin >> acno;

	ifstream inFile;
	inFile.open("account.dat", ios::binary);
	while (!inFile.eof())
	{
		inFile.read(reinterpret_cast<char *> (&ac), sizeof(account));
		if (ac.retacno() == acno)
		{
			system("cls");
			l++;
			cout << "\n\n\t\t\tThere's Already An Account With The Same Account Number.\n\n\t\t\t Enter A Different Account Number.";
			inFile.close();
			cin.get();
			cin.get();
			break;

		}
		else{
			continue;
		}
	}

	if (l != 0)return l;
	inFile.close();
	cout << "\n\n\t\t\tEnter The Name of The account Holder : ";
	cin.ignore();
	cin.getline(name, 100);
	cout << "\n\t\t\tEnter Type of The account (C/S) : ";
	cin >> type;
	type = toupper(type);
	while (1)
	{
		cout << "\n\t\t\tEnter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
		cin >> deposit;
		if (type == 'S' && deposit < 500)
		{
			cout << "\n\n\t\t\tInvalid Input, Please Re-enter Initial Amount: ";

			cin.get();
			continue;
		}
		else if (type == 'C' && deposit < 1000)
		{
			cout << "\n\n\t\t\tInvalid Input, Please Re-enter Initial Amount: ";

			cin.get();
			continue;
		}
		else
		{
			break;
		}
	}
	cout << "\n\n\t\t\tEnter the password to be given: ";
	cin >> password;
	cout << "\n\n\n\t\t\tAccount Created..";
	cin.get();
	cin.get();

	return l;
}

void account::modify()
{
	cout << "\n\t\t\tAccount No. : " << acno;
	cout << "\n\t\t\tModify Account Holder Name : ";
	cin.ignore();
	cin.getline(name, 100);
	cout << "\n\t\t\tModify Type of Account : ";
	cin >> type;
	type = toupper(type);
	cout << "\n\t\t\tModify Balance amount : ";
	cin >> deposit;
}


void account::show_account() const
{
	cout << "\n\t\t\tAccount No. : " << acno;
	cout << "\n\t\t\tAccount Holder Name : ";
	cout << name;
	cout << "\n\t\t\tType of Account : " << type;
	cout << "\n\t\t\tBalance amount : " << deposit;
	cin.get();
	cin.get();
}

void account::dep(int x)
{
	deposit += x;
}

void account::draw(int x)
{
	deposit -= x;
}

void account::report() const
{
	cout << "                       " << acno << setw(10) << " " << name << setw(10) << type << setw(10) << " " << deposit << endl;
}


int account::retacno() const
{
	return acno;
}

int account::retdeposit() const
{
	return deposit;
}

int account::retpass() const
{
	return password;
}

char account::rettype() const
{
	return type;
}



account::~account()
{
}
